#region Using
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using ghrb.States;
using ghrb.Managers;
#endregion

namespace ghrb
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        #region Public Functions
        /// <summary>
        /// Constructor
        /// </summary>
        public Game1()
        {
            //Set Graphics device manager
            graphics = new GraphicsDeviceManager(this);

            //Set Content directory
            Content.RootDirectory = "Content";

            //Set screen size
            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth = 1280;

            //Set windowed mode
            graphics.IsFullScreen = false;

            //Set mouse visible
            IsMouseVisible = true;
        }
        #endregion

        #region Protected Functions
        /// <summary>
        /// Non-graphic initialize
        /// </summary>
        protected override void Initialize()
        {
            //Create MainMenu
            m_MainMenuState = new StateMainMenu(this);
            m_GameState = new StateGame(this);

            //Set current state to main menu
            m_CurrentState = m_GameState;

            //Load input managers
            m_InputManagers[0] = new InputManager(PlayerIndex.One);
            m_InputManagers[1] = new InputManager(PlayerIndex.Two);
            m_InputManagers[2] = new InputManager(PlayerIndex.Three);
            m_InputManagers[3] = new InputManager(PlayerIndex.Four);

            base.Initialize();
        }

        /// <summary>
        /// Load content
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Load font
            m_fontFightingSpirit = Content.Load<SpriteFont>("Fonts/FightingSpirit");

            //Load content of the states
            m_CurrentState.LoadContent(Content);
        }

        /// <summary>
        /// Update all
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Update current state
            m_CurrentState.Update(gameTime);

            //Update all inputs
            foreach (InputManager ipm in m_InputManagers)
                ipm.Update(gameTime);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            //Clear background
            GraphicsDevice.Clear(Color.White);

            //Draw current state
            m_CurrentState.Draw();

            base.Draw(gameTime);
        }
        #endregion

        #region Properties and Vars
        /// <summary>
        /// Graphics device manager
        /// </summary>
        private GraphicsDeviceManager graphics = null;

        /// <summary>
        /// Fifghting Spirit font
        /// </summary>
        public SpriteFont FSP
        {
            get { return m_fontFightingSpirit; }
        }
        private SpriteFont m_fontFightingSpirit = null;

        /// <summary>
        /// Spritebatch
        /// </summary>
        public SpriteBatch SpriteBatch
        {
            get { return spriteBatch; }
        }
        private SpriteBatch spriteBatch = null;

        /// <summary>
        /// All players input managers
        /// </summary>
        public InputManager[] GetInputManagers
        {
            get { return m_InputManagers; }
        }
        private InputManager[] m_InputManagers = new InputManager[4];

        #region States
        /// <summary>
        /// Current state
        /// </summary>
        private State m_CurrentState = null;

        /// <summary>
        /// Main menu state
        /// </summary>
        private StateMainMenu m_MainMenuState = null;

        /// <summary>
        /// Game state
        /// </summary>
        private StateGame m_GameState = null;
        #endregion
        #endregion
    }
}
